package com.breakfast.fun.ui.mall.address;

import android.widget.Button;
import android.widget.EditText;

import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseActivity;
import com.breakfast.fun.base.BaseModel;
import com.breakfast.fun.base.BasePresenter;
import com.breakfast.fun.event.MallAddressEvent;
import com.breakfast.fun.util.T;
import com.breakfast.fun.view.widget.TitleBarView;

import org.greenrobot.eventbus.EventBus;

import butterknife.Bind;

public class MallAddressActivity extends BaseActivity<BasePresenter, BaseModel> {

    @Bind(R.id.tbv_mall_address)
    TitleBarView mTbvMallAddress;
    @Bind(R.id.et_mall_address_name)
    EditText mEtMallAddressName;
    @Bind(R.id.et_mall_address_mobile)
    EditText mEtMallAddressMobile;
    @Bind(R.id.et_mall_address_detail)
    EditText mEtMallAddressDetail;
    @Bind(R.id.btn_add_mall_address)
    Button mBtnAddMallAddress;

    @Override
    public int getLayoutId() {
        return R.layout.activity_mall_address;
    }

    @Override
    public void initView() {
        mTbvMallAddress.setTitleNoRight("填写收货地址");
        mTbvMallAddress.setBack(this);

        mBtnAddMallAddress.setOnClickListener(v -> {
            if (mEtMallAddressMobile.getText().length() != 11) {
                T.show("请填写正确的手机号码");
                return;
            }
            if (mEtMallAddressName.getText().length() == 0
                    || mEtMallAddressDetail.getText().length() == 0) {
                T.show("请将信息填写完整");
                return;
            }
            MallAddressEvent event = new MallAddressEvent();
            event.setDetail(mEtMallAddressDetail.getText().toString());
            event.setMobile(mEtMallAddressMobile.getText().toString());
            event.setName(mEtMallAddressName.getText().toString());
            EventBus.getDefault().post(event);
            MallAddressActivity.this.finish();
        });
    }

}
